package momo.pagri.util;

import junit.framework.TestCase;

public class ZipfDistributionAdapterTest extends TestCase {

	public static void main(String[] args) {
		junit.textui.TestRunner.run(ZipfDistributionAdapterTest.class);
	}

	/*
	 * Test method for 'pagri.util.ZipfDistributionAdapter.cumulativeProbability(double)'
	 */
	public void testCumulativeProbabilityDouble() throws Exception {
		ZipfDistributionAdapter zd = new ZipfDistributionAdapter(new ZipfDistribution(1, 5));
		
		double denom = 1.0 + 1.0/2.0 + 1.0/3.0 + 1.0 / 4.0 + 1.0 / 5.0;
		assertEquals(1.0 / denom, zd.cumulativeProbability(1.0), 0.00001);
		assertEquals(1.0, zd.cumulativeProbability(5.0), 0.00001);

	}

	/*
	 * Test method for 'pagri.util.ZipfDistributionAdapter.inverseCumulativeProbability(double)'
	 */
	public void testInverseCumulativeProbability() throws Exception {
		ZipfDistributionAdapter zd = new ZipfDistributionAdapter(new ZipfDistribution(1, 5));
		double denom = 1.0 + 1.0/2.0 + 1.0/3.0 + 1.0 / 4.0 + 1.0 / 5.0;
		assertEquals(0.0, zd.inverseCumulativeProbability(0));
		assertEquals(0.0, zd.inverseCumulativeProbability(0.2));
		assertEquals(2.0, zd.inverseCumulativeProbability(0.8));
		assertEquals(1.0, zd.inverseCumulativeProbability(0.00004 + 1.0 / denom ));
		assertEquals(5.0, zd.inverseCumulativeProbability(1));
	}

}
